package com.pf.java.ThreadTest;

import sun.security.rsa.RSAUtil;

/**
 * 线程的生命周期
 *
 * ClassName:Thread02
 * Package:com.pf.java.ThreadTest
 *
 * @author: pf
 * @date: 2021/11/22-9:21
 */
public class Thread02 {

    public static void main(String[] args) throws InterruptedException {

        // 新建
        Thread thread0 = new Thread(new ThreadTask());
        Thread thread1 = new Thread(new ThreadTask());

        for (int i = 0; i < 100; i++) {
            System.out.println(Thread.currentThread().getName() + "   " +i);
            if(i == 10) {
                // 子线程就绪
                thread0.start();
                thread1.start();

                // 主线程就绪
//                Thread.yield();
                // 主线程阻塞
                Thread.sleep(1);
            }


            // 子线程死亡
//            thread0.start();
//            thread1.start();

            // 只能对新建状态的线程调用start()
        }
    }

    private static class ThreadTask implements Runnable {

        @Override
        public void run() {
            for (int i = 0; i < 10; i++) {
                System.out.println(Thread.currentThread().getName() + "  " + i);
            }
        }
    }

}
